const { validationResult, oneOf } = require("express-validator");
const { SuccessSend } = require("../utils/response");
const user = require("./user");
const banner = require("./banner");
const notice = require("./notice");

const Validate = (rules) => {
    return [
        ...rules,
        (req, res, next) => {
            const errors = validationResult(req);
            if (!errors.isEmpty()) {
                return SuccessSend(res, {
                    code: -1,
                    success: false,
                    message: errors.array().map((error) => error.msg),
                });
            }
            next();
        },
    ];
};

module.exports = { Validate, user, banner, notice };
